﻿/**************************************
* Copyright by Spring Studio(http://springstudio.cn)
* 分页专用脚本
***************************************/

function Pagination_CheckIsNumber(str) {
    if (str.length == 0) {
        return false;
    }

    var isNumber = 0;

    for (i = 0; i < str.length; i++) {
        isNumber = 0; //先把isNumber置为0

        for (j = 0; j < 10; j++) {
            if (str.charAt(i) == "" + j)
                isNumber = 1; //找到匹配的数字项，则置为1
        }

        if (isNumber == 0)	//找不到匹配的数字，则返回false
            return false;
    }

    return true; //完成检查，返回true
}

function Pagination_Navigate() {
    if (!Pagination_CheckIsNumber(document.getElementById("PageIndex").value)) {
        alert("页码必须是正整数，并且不能为空！");
        document.getElementById("PageIndex").value = "";
        document.getElementById("PageIndex").focus();
        return;
    }

    if (document.getElementById("PageIndex").value - document.getElementById("PageCount").value > 0) {
        alert("页码必须不大于总页数！");
        document.getElementById("PageIndex").value = "";
        document.getElementById("PageIndex").focus();
        return;
    }

    if (document.getElementById("PageIndex").value == 0) {
        alert("页码必须大于零！");
        document.getElementById("PageIndex").value = "";
        document.getElementById("PageIndex").focus();
        return;
    }

    if (document.location.href.search(/PageIndex=[0-9]+/) > -1) {
        document.location.href = document.location.href.replace(/PageIndex=[0-9]+/, "PageIndex=" + document.getElementById("PageIndex").value);
    }
    else {
        if (document.location.href.indexOf("?") > -1) {
            document.location.href = document.location.href + "&PageIndex=" + document.getElementById("PageIndex").value;
        }
        else {
            document.location.href = document.location.href + "?PageIndex=" + document.getElementById("PageIndex").value;
        }
    }

    if (document.location.href.search(document.getElementById("UrlAddOn").value) < 0) {
        document.location.href += document.getElementById("UrlAddOn").value;
    }
}